package com.aurora.blog.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.aurora.common.log.annotation.Log;
import com.aurora.common.log.enums.BusinessType;
import com.aurora.common.security.annotation.RequiresPermissions;
import com.aurora.blog.domain.BlogCategories;
import com.aurora.blog.service.IBlogCategoriesService;
import com.aurora.common.core.web.controller.BaseController;
import com.aurora.common.core.web.domain.AjaxResult;
import com.aurora.common.core.utils.poi.ExcelUtil;
import com.aurora.common.core.web.page.TableDataInfo;

/**
 * 分类Controller
 * 
 * @author aurora
 * @date 2024-06-27
 */
@RestController
@RequestMapping("/blogCategories")
public class BlogCategoriesController extends BaseController
{
    @Autowired
    private IBlogCategoriesService blogCategoriesService;

    /**
     * 查询分类列表
     */
    @RequiresPermissions("blog:blogCategories:list")
    @GetMapping("/list")
    public TableDataInfo list(BlogCategories blogCategories)
    {
        startPage();
        List<BlogCategories> list = blogCategoriesService.selectBlogCategoriesList(blogCategories);
        return getDataTable(list);
    }
    /**
     * 查询分类列表
     */
    @GetMapping("/getBlogCategoriesList")
    public AjaxResult getBlogCategoriesList(BlogCategories blogCategories)
    {
        List<BlogCategories> list = blogCategoriesService.selectBlogCategoriesList(blogCategories);
        return success(list);
    }

    /**
     * 导出分类列表
     */
    @RequiresPermissions("blog:blogCategories:export")
    @Log(title = "分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BlogCategories blogCategories)
    {
        List<BlogCategories> list = blogCategoriesService.selectBlogCategoriesList(blogCategories);
        ExcelUtil<BlogCategories> util = new ExcelUtil<BlogCategories>(BlogCategories.class);
        util.exportExcel(response, list, "分类数据");
    }

    /**
     * 获取分类详细信息
     */
    @RequiresPermissions("blog:blogCategories:query")
    @GetMapping(value = "/{categoryId}")
    public AjaxResult getInfo(@PathVariable("categoryId") Long categoryId)
    {
        return success(blogCategoriesService.selectBlogCategoriesByCategoryId(categoryId));
    }

    /**
     * 新增分类
     */
    @RequiresPermissions("blog:blogCategories:add")
    @Log(title = "分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BlogCategories blogCategories)
    {
        return toAjax(blogCategoriesService.insertBlogCategories(blogCategories));
    }

    /**
     * 修改分类
     */
    @RequiresPermissions("blog:blogCategories:edit")
    @Log(title = "分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BlogCategories blogCategories)
    {
        return toAjax(blogCategoriesService.updateBlogCategories(blogCategories));
    }

    /**
     * 删除分类
     */
    @RequiresPermissions("blog:blogCategories:remove")
    @Log(title = "分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{categoryIds}")
    public AjaxResult remove(@PathVariable Long[] categoryIds)
    {
        return toAjax(blogCategoriesService.deleteBlogCategoriesByCategoryIds(categoryIds));
    }
}
